#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<stdbool.h>
using namespace std;

class Solution {
public:
    vector<vector<int>> ret;
    vector<int> path;
    bool used[7];
    void dfs(vector<int>& nums)
    {
        if (nums.size() == path.size())
        {
            ret.push_back(path);
            return;
        }
        for (int i = 0; i < nums.size(); ++i)
        {
            if (!used[i])
            {
                path.push_back(nums[i]);
                used[i] = true;
                dfs(nums);
                path.pop_back();
                used[i] = false;
            }
        }
    }
    vector<vector<int>> permute(vector<int>& nums) {
        dfs(nums);
        return ret;
    }

    bool canMakeSquare(vector<vector<char>>& grid) {
        for (int i = 0; i < 3; ++i)
        {
            for (int j = 0; j < 3; ++j)
            {
                if (i < 2 && j < 2 && grid[i][j] == grid[i + 1][j] && grid[i][j] == grid[i][j + 1]) return true;
                else if (i > 0 && j > 0 && grid[i][j] == grid[i - 1][j] && grid[i][j] == grid[i][j - 1]) return true;
                else if (i > 0 && j < 2 && grid[i][j] == grid[i - 1][j] && grid[i][j] == grid[i][j + 1]) return true;
                else if (j > 0 && i < 2 && grid[i][j] == grid[i][j - 1] && grid[i][j] == grid[i + 1][j]) return true;
            }
        }
        return false;
    }

    int myAtoi(string s) {
        long long num = 0, i = 0;
        int n = s.length();
        while (i < n && s[i] == ' ') ++i;
        if (i == n) return 0;

        int flag = 1;
        if (s[i] == '-')
        {
            flag = -1;
            ++i;
        }
        else if (s[i] == '+') ++i;
        while (i < n && s[i] == '0') ++i;
        if (i == n) return 0;
        for (; i < n; ++i)
        {
            char c = s[i];
            if (c < '0' || c>'9') break;
            num = num * 10 + (c - '0');
            long long v = num * flag;
            if (v >= INT_MAX) return INT_MAX;
            if (v <= INT_MIN) return INT_MIN;
        }
        return num * flag;
    }
};